﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Barbar.UrlGuard.BL;

namespace Barbar.UrlGuard.Controls {
  public class LocalizableForm : Form {
    protected override void OnLoad(EventArgs e) {
      base.OnLoad(e);
      if (!this.DesignMode) {
        ITranslator translator = ServiceLocator.Instance.Resolve<ITranslator>();
        translator.Localize(this);

        ILanguageObserver observer = ServiceLocator.Instance.Resolve<ILanguageObserver>();
        observer.LanguageChanged += new EventHandler(observer_LanguageChanged);
      }
    }

    protected override void OnClosed(EventArgs e) {
      ILanguageObserver observer = ServiceLocator.Instance.Resolve<ILanguageObserver>();
      observer.LanguageChanged -= new EventHandler(observer_LanguageChanged);
      base.OnClosed(e);
    }

    private void observer_LanguageChanged(object sender, EventArgs e) {
      ITranslator translator = ServiceLocator.Instance.Resolve<ITranslator>();
      translator.Localize(this);
    }
  }
}
